<?php

namespace api\modules\user\models;

use Yii;
use yii\data\ActiveDataProvider;
use common\models\user\UserFollower;

class FollowSearch extends UserFollower {
    private $_token;
    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params = []) {

        $query = static::find()->where([
            'user_id' => $this->_token->user_id,
        ])->orderBy('listorder desc,created_at desc');
        $query->with(['followUser']);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        return $dataProvider;
    }

    public function fields() {
        return [
            'id',
            'followed_user_info'=>'followUser',
            'remark',
            'created_at'
        ];
    }

    public function setToken($token){
        $this->_token = $token;
        return $this;
    }

}